package com.silong.swing.myWindows;

import javax.swing.*;
import java.awt.*;

/**
 * Created by 龙哥 on 2022-01-17 15:02
 * Silong Software.
 * 创建自定义边框布局
 *
 */

public class MyFrameByBorderLayout extends JFrame {

    JButton button1;
    JButton button2;
    JButton button3;
    JButton button4;
    JButton button5;

    public MyFrameByBorderLayout(){
        init();
    }

    private void init(){

        button1 = new JButton("按钮一");
        button2 = new JButton("按钮二");
        button3 = new JButton("按钮三");
        button4 = new JButton("按钮四");
        button5 = new JButton("按钮五");

        Container window = this.getContentPane();
        this.setSize(800, 600);
        this.setLocationRelativeTo(null); //距中
        this.setTitle("BorderLayout边框布局窗体");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //退出窗口关闭程序

        //设置窗体的布局的边框式，东南西北中，50为水平边距，垂直边距
        window.setLayout(new BorderLayout(10,5));

        //每个区域只能存放一个部件，BorderLayout.CENTER可以占边框，边框不可以占中间
        //中间可以接管地方
        window.add(button1, BorderLayout.EAST);
        window.add(button2, BorderLayout.SOUTH);
        window.add(button3, BorderLayout.WEST);
        window.add(button4, BorderLayout.NORTH);
        window.add(button5, BorderLayout.CENTER);

    }

}
